package com.wwf;

import com.wwf.filter.com.wwf.util.TpCount;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

public class JobReport {
    public static void main(String[] args) {
        test03();
    }
    public static void test03(){
        TreeMap<Long, Long> treeMap = new TreeMap<>(Comparator.naturalOrder());
        // <1,1> <5,3> <6,1> <2,2> <3,3> <4,2> <7,2> <9,3> <10,3>
        treeMap.put(1l,1l);
        treeMap.put(5l,3l);
        treeMap.put(6l,1l);
        treeMap.put(2l,2l);
        treeMap.put(3l,100l);
        treeMap.put(4l,2l);
        treeMap.put(7l,2l);
        treeMap.put(9l,3l);
        treeMap.put(10l,3l);

        TreeMap<Long, Long> transMap = new TreeMap<>(Comparator.naturalOrder());
        AtomicReference<Long> idx= new AtomicReference<>(0l);
        treeMap.forEach((key,value)->{
            transMap.put(idx.get(),key);
            idx.updateAndGet(v -> v + value);
        });

        Long total=treeMap.values().stream().mapToLong(o->o).sum();
        Double idx90= Math.ceil((double)total*90/100);
        Double idx95= Math.ceil((double)total*95/100);
        Double idx99= Math.ceil((double)total*99/100);
        Map.Entry<Long, Long> idx90Entry = transMap.floorEntry(idx90.longValue());
        Map.Entry<Long, Long> idx95Entry = transMap.floorEntry(idx95.longValue());
        Map.Entry<Long, Long> idx99Entry = transMap.floorEntry(idx99.longValue());

        Long TP90=idx90Entry.getValue();
        Long TP95=idx95Entry.getValue();
        Long TP99=idx99Entry.getValue();

        System.out.println("TP90:"+TP90+", TP95:"+TP95+", TP99:"+TP99);
    }
}
